﻿
namespace K9Nano.Remoting
{
    public interface IApiInfo
    {
        /// <summary>
        /// 监听对口
        /// </summary>
        int HttpPort { get; }

        /// <summary>
        /// 监听对口
        /// </summary>
        int GrpcPort { get; }

        /// <summary>
        /// API资源名称，唯一
        /// </summary>
        string Name { get; }

        /// <summary>
        /// 秘钥
        /// </summary>
        string Secret { get; }

        /// <summary>
        /// 友好名称
        /// </summary>
        string DisplayName { get; }
        
        /// <summary>
        /// 版本
        /// </summary>
        string Version { get; }
    }

    public class ApiInfo: IApiInfo
    {
        public int HttpPort { get; set; }
        public int GrpcPort { get; set; }
        public string Name { get; set; }
        public string Secret { get; set; }
        public string DisplayName { get; set; }
        public string Version { get; set; } = "1.0";

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is IApiInfo other)
            {
                return Name == other.Name;
            }

            return false;
        }

        public static bool operator ==(ApiInfo left, IApiInfo right)
        {
            if (Equals(left, null))
            {
                return Equals(right, null);
            }

            return left.Equals(right);
        }

        public static bool operator !=(ApiInfo left, IApiInfo right)
        {
            return !(left == right);
        }

        public override string ToString()
        {
            return $"DisplayName: {DisplayName}, Name: {Name}, HttpPort: {HttpPort}, GrpcPort: {GrpcPort}, Version: {Version}";
        }
    }
}
